# -*- coding:utf-8 -*-
import datetime
import threading
import time

import schedule


def job1():
    print("I'm working for job1 start", datetime.datetime.now())
    time.sleep(5)
    print("job1: end", datetime.datetime.now())


def job2():
    print("I'm working for job2 start", datetime.datetime.now())
    time.sleep(3)
    print("job2: end", datetime.datetime.now())


def job1_task():
    threading.Thread(target=job1).start()


def job2_task():
    threading.Thread(target=job2).start()


def mutil_run():
    schedule.every(3).seconds.do(job1_task)
    schedule.every(3).seconds.do(job2_task)

    while True:
        schedule.run_pending()
        time.sleep(1)


def job(text=""):
    print(text, "I'm working...")


def single_run():
    schedule.every().seconds.do(job, "每秒一次")
    schedule.every(5).seconds.do(job, "五秒一次")
    schedule.every(10).minutes.do(job, "10分钟一次")
    schedule.every().hour.do(job, "1小时一次")
    # 每天10:30执行
    schedule.every().day.at("10:30").do(job)
    # 每隔5到10天执行一次任务
    schedule.every(5).to(10).days.do(job)
    # 每周一的这个时候执行一次任务
    schedule.every().monday.do(job)
    # 每周三13:15执行一次任务
    schedule.every().wednesday.at("13:15").do(job)

    while True:
        # run_pending：运行所有可以运行的任务
        schedule.run_pending()
        time.sleep(1)


if __name__ == '__main__':
    single_run()
